package handler

import (
	"context"

	"gitee.com/segeln/grit"
	"gitee.com/segeln/grit/log"

	pb "gitee.com/segeln/grit/example/protoc"
)

//定义一个helloServer并实现约定的接口
type helloService struct{}

func (h helloService) SayHello(ctx context.Context, in *pb.HelloReq) (*pb.HelloRep, error) {
	resp := new(pb.HelloRep)
	resp.Rep = "SayHello : " + in.Req

	info, err := grit.CurrentRegistry.SelectorService("user", "")
	if err != nil {
		log.Errorln("getservices failed,error:", err)
	}
	log.Errorln("info:", info.Name, ",id:", info.ID, ",version:", info.Version, ",usecount:", info.UseCount)
	/*
		for _, info := range serinfos {

			log.Errorln("info:", info.Name, ",id:", info.ID)
		}
	*/
	return resp, nil
}
func (h helloService) CallHello(ctx context.Context, in *pb.HelloReq) (*pb.HelloRep, error) {
	resp := new(pb.HelloRep)
	resp.Rep = "CallHello : " + in.Req
	return resp, nil
}

var HelloServer = helloService{}
